package com.simtop.service.impl;

import com.simtop.dao.ApiMapper;
import com.simtop.pojo.SwyDone;
import com.simtop.pojo.SwyDone2;
import com.simtop.pojo.YongdaoPo;
import com.simtop.pojo.newOneListVo;
import com.simtop.pojo.wddata.MainTain;
import com.simtop.pojo.wddata.WdDate;
import com.simtop.pojo.wddata.api;
import com.simtop.service.ApiService;
import com.simtop.vo.Echarts3Vo;
import com.simtop.vo.MessageVo;
import com.simtop.vo.Swread;
import com.simtop.vo.UserVoS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class ApiServerImpl implements ApiService {

    @Autowired
    private ApiMapper apiMapper;


    @Override
    public void saverapi(String data, String createtime, String plant) {
          apiMapper.saverapi(data,createtime,plant);
    }

    @Override
    public api findAlldevice() {
        return apiMapper.findAlldevice();
    }

    @Override
    public boolean managedata(List<WdDate> lastDate, String plant) {
        for (WdDate aa:lastDate
             ) {
            aa.setDeviceplant(plant);
            Integer tss = aa.getTss();
            String timestampString = String.valueOf(tss);
            //String formats = "yyyy-MM-dd HH:mm:ss";
            Long timestamp = Long.parseLong(timestampString) * 1000;
            Date date = new Date(timestamp);
            System.out.println(date);
            aa.setDevicetime(date);
            //System.out.println(date);
            //日期格式字符串
            //String dateStr = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp));
            //当然 没有id是不行的 取一个万能id作为链表查询
            //温湿度 id 1
            //核心
            if(aa.getTnm().contains("WSD")){
                //说明他是温湿度
                //拆解string
                //WSD_1_WD
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("WSD_"+ deviceid);
                //判断类型是什么
                if(tnm.endsWith("WD")){
                    aa.setDevicetype("温度");
                    Float val = aa.getVal();
                    aa.setVal(val/10);
                }else if(tnm.endsWith("SD")){
                    aa.setDevicetype("湿度");
                    Float val = aa.getVal();
                    aa.setVal(val/10);
                }
            }else if(aa.getTnm().contains("LZ")){
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("LZ_"+ deviceid);
                //获取类型
                if(tnm.endsWith("YC")){
                    aa.setDevicetype("压差");
                    Float val = aa.getVal();
                    aa.setVal(val/10);
                }
            }else if(aa.getTnm().contains("FS")){
                String tnm = aa.getTnm();
                Integer deviceid = Integer.valueOf(tnm.split("_")[1]);
                //System.out.println(deviceid);
                aa.setDeviceid(deviceid);
                aa.setDevicename("FS_"+ deviceid);
                //获取类型
                if(tnm.endsWith("FS")){
                    aa.setDevicetype("风速");
                    Float val = aa.getVal();
                    aa.setVal(val/1000);
                }

            }


        }


        boolean  savedata = apiMapper.savedata(lastDate);

        return  savedata;

    }

    @Override
    public List<MainTain> findAlldeviceList() {
        return apiMapper.findAlldeviceList();
    }

    @Override
    public WdDate findDeviceValue(int deviceId,String testType) {
        return apiMapper.findDeviceValue(deviceId,testType);
    }

    @Override
    public WdDate findDeviceStatusValue(int deviceId) {
        return apiMapper.findDeviceStatusValue(deviceId);
    }

    @Override
    public void updateDevice(Integer deviceId,String devicepolicelist, String testLocation, Integer deviceNormalup, Integer devicePolicedown) {
        apiMapper.updateDevice(deviceId , devicepolicelist, testLocation, deviceNormalup, devicePolicedown);
    }

    @Override
    public void insertYongdao(List<YongdaoPo> YongDao) {
        apiMapper.insertYongdao(YongDao);
    }

    @Override
    public List<SwyDone> findAllSwyDone() {
        return apiMapper.findAllSwyDone();
    }

    @Override
    public List<SwyDone> findAllSwyDone1() {
        return apiMapper.findAllSwyDone1();
    }

    @Override
    public List<SwyDone2> findAllSwyDone2() {
        return apiMapper.findAllSwyDone2();
    }

    @Override
    public void deletesw() {
         apiMapper.deletesw();
    }

    @Override
    public void deletesws() {
        apiMapper.deletesws();
    }

    @Override
    public void insertfxuser(Integer swuserid, String data) {
        apiMapper.insertfxuser(swuserid,data);
    }

    @Override
    public newOneListVo findOneFx(Integer swuserid) {
     return    apiMapper.findOneFx(swuserid);
    }

    @Override
    public void changeOne(Integer swuserid) {
        apiMapper.changeOne(swuserid);
    }

    @Override
    public int findAllSwyDoneOne() {
        return apiMapper.findAllSwyDoneOne();
    }

    @Override
    public void changeOneStatus() {
        apiMapper.changeOneStatus();
    }

    @Override
    public void changeOneStatus2() {
        apiMapper.changeOneStatus2();
    }

    @Override
    public int finids(Integer swuserid) {
        return apiMapper.finids(swuserid);
    }

    @Override
    public void changezbStatus(int lastid) {
        apiMapper.changezbStatus(lastid);
    }

    @Override
    public int selectStatus() {
        return apiMapper.selectStatus();
    }

    @Override
    public void changeStatus1() {
        apiMapper.changeStatus1();
    }

    @Override
    public void changeStatus2() {
        apiMapper.changeStatus2();
    }

    @Override
    public void changeOneStatus2s() {
        apiMapper.changeOneStatus2s();
    }

    @Override
    public int finStatuszt() {
        return apiMapper.finStatuszt();
    }

    @Override
    public int findTameid(String userteam) {
        return apiMapper.findTameid(userteam);
    }

    @Override
    public void saveAlluser(List<UserVoS> userVoSArrayList) {
         apiMapper.saveAlluser(userVoSArrayList);
    }

    @Override
    public void updateBackendUser(UserVoS user) {
        apiMapper.updateBackendUser(user);
    }

    @Override
    public void saveBegin(String formatbegin) {
        apiMapper.saveBegin(formatbegin);
    }

    @Override
    public void saveEnd(String formatend, Integer swuserid) {
        apiMapper.saveEnd(formatend,swuserid);
    }

    @Override
    public int getid(Integer swuserid) {
        return apiMapper.getid(swuserid);
    }

    @Override
    public void getStartTime(int last ,String formatend) {
        apiMapper.getStartTime(last , formatend);
    }

    @Override
    public List<Swread> swreadList() {
        return  apiMapper.swreadList();
    }

    @Override
    public void asveAllread(List<Swread> swreadList) {
         apiMapper.asveAllread(swreadList);
    }

    @Override
    public List<Swread> findsw(String tameName, String types, String readTimeBegins, String readTimeEnds,String column , String order) {
      return   apiMapper.findsw(tameName,types,readTimeBegins,readTimeEnds,column ,order);
    }

    @Override
    public int getOne(Integer userId) {
        return apiMapper.getOne(userId);
    }

    @Override
    public void changeUser(Integer id) {
        apiMapper.changeUser(id);
    }

    @Override
    public void changeScore(Integer score , Integer swuserid) {
        apiMapper.changeScore(score , swuserid);
    }

    @Override
    public List<Swread> findSwread() {
        return apiMapper.findSwread();
    }

    @Override
    public List<Swread> findSwread2(ArrayList<Integer> sqsyidlist) {
        return apiMapper.findSwread2(sqsyidlist);
    }

    @Override
    public Echarts3Vo findScore() {
        return apiMapper.findScore();
    }

    @Override
    public Echarts3Vo findContent() {
        return apiMapper.findContent();
    }

    @Override
    public List<String> findGroupTime() {
        return apiMapper.findGroupTime();
    }

    @Override
    public Integer dinOneCount(String as) {
        return apiMapper.dinOneCount(as);
    }

    @Override
    public MessageVo findmessage() {
        return apiMapper.findmessage();
    }

    @Override
    public void changemessage(Integer status, String swContent) {
        apiMapper.changemessage(status , swContent);
    }

    @Override
    public void deletestatusByid(Integer swuserid) {
        apiMapper.deletestatusByid(swuserid);
    }


    @Override
    public void saveAllcxList(List<SwyDone> yongdaoPoList) {
        apiMapper.saveAllcxList(yongdaoPoList);
    }




}
